package customerService

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/pkg/code"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/client/customerservicegroup"
	"github.com/zeromicro/go-zero/core/logc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CustomerServiceGroupInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 客服群管理详情
func NewCustomerServiceGroupInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CustomerServiceGroupInfoLogic {
	return &CustomerServiceGroupInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CustomerServiceGroupInfoLogic) CustomerServiceGroupInfo(req *types.Empty) (resp *types.CustomerServiceGroupInfoData, err error) {
	u, err := l.svcCtx.SettingService.CustomerService.CustomerServiceGroupInfo(l.ctx, &customerservicegroup.CustomerServiceGroupInfoReq{MerchantId: 1, Status: -1})

	if err != nil {
		logc.Error(l.ctx, "CustomerServiceGroupInfo err:", err)
		return nil, err
	}

	if u.Code != int64(code.SettingRpcSuccessful.Code()) {
		return nil, code.BusinessFailure
	}

	if u.Data.Id == 0 {
		return nil, code.NotData
	}

	return &types.CustomerServiceGroupInfoData{
		CommunicationType: u.Data.CommunicationType,
		Id:                u.Data.Id,
		MerchantId:        u.Data.MerchantId,
		GroupPic:          u.Data.GroupPic,
		Title:             u.Data.Title,
		Subheading:        u.Data.Subheading,
		JumpAddress:       u.Data.JumpAddress,
		Status:            u.Data.Status,
	}, nil
}
